package com.zreal.generator.codegenerate.database;

import java.util.List;

/**
 * 表对象
 * <p>
 * Created 2018/2/6.
 *
 * @author PJ
 */
public class Table {
    /**
     * 主键
     */
    private String primaryKey;
    /**
     * 类名，驼峰
     */
    private String className;
    /**
     * 数据库表名
     */
    private String tableName;
    /**
     * 表备注
     */
    private String tableComment;
    /**
     * 表字段
     */
    private List<Column> columns;

    private String selectkeys;

    public String getTableSql() {
        StringBuilder reStr = new StringBuilder();
        reStr.append("SELECT ");
        int i = 1;
        for (Column c : columns) {
            reStr.append("a.");
            if (i == columns.size()) {
                reStr.append(c.getFieldName());
            } else {
                reStr.append(c.getFieldName()).append(",");
            }
            i++;
        }
        return reStr.toString();
    }

    public String getSelectKeys() {
        StringBuilder reStr = new StringBuilder();
        int i = 1;
        for (Column c : columns) {
            reStr.append("a.");
            if (i == columns.size()) {
                reStr.append(c.getFieldDbName());
            } else {
                reStr.append(c.getFieldDbName()).append(",");
            }
            i++;
        }
        return reStr.toString();
    }


    public String getPrimaryKey() {
        return primaryKey;
    }

    public void setPrimaryKey(String primaryKey) {
        this.primaryKey = primaryKey;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getTableComment() {
        return tableComment;
    }

    public void setTableComment(String tableComment) {
        this.tableComment = tableComment;
    }

    public List<Column> getColumns() {
        return columns;
    }

    public void setColumns(List<Column> columns) {
        this.columns = columns;
    }

    public String getSelectkeys() {
        return selectkeys;
    }

    public void setSelectkeys(String selectkeys) {
        this.selectkeys = selectkeys;
    }

    @Override
    public String toString() {
        return "Table{" +
                "primaryKey='" + primaryKey + '\'' +
                ", className='" + className + '\'' +
                ", tableName='" + tableName + '\'' +
                ", tableComment='" + tableComment + '\'' +
                ", columns=" + columns +
                ", selectkeys='" + getSelectKeys() + '\'' +
                '}';
    }
}
